<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        
        
        
        <link rel="shortcut icon" href="../img/favicon.ico">
        <title>web3.db - Web3.js 0.20官方文档中文版</title>
        <link href="../css/bootstrap-custom.min.css" rel="stylesheet">
        <link href="../css/font-awesome.min.css" rel="stylesheet">
        <link href="../css/base.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
        <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
            <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->

        <script src="../js/jquery-1.10.2.min.js" defer></script>
        <script src="../js/bootstrap-3.0.3.min.js" defer></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
        <script>hljs.initHighlightingOnLoad();</script> 
    </head>

    <body>

        <div class="navbar navbar-default navbar-fixed-top" role="navigation">
            <div class="container">

                <!-- Collapsed navigation -->
                <div class="navbar-header">
                    <!-- Expander button -->
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="..">Web3.js 0.20官方文档中文版</a>
                </div>

                <!-- Expanded navigation -->
                <div class="navbar-collapse collapse">
                        <!-- Main navigation -->
                        <ul class="nav navbar-nav">
                            <li >
                                <a href="https://web3.learnblockchain.cn">首页</a>
                            </li>
                            <li >
                                <a href="..">0.20文档</a>
                            </li>
                            <li >
                                <a href="https://learnblockchain.cn">深入浅出区块链</a>
                            </li>
                            <li >
                                <a href="https://wiki.learnblockchain.cn/images/dapp.png">DAPP视频课程</a>
                            </li>
                        </ul>

                    <ul class="nav navbar-nav navbar-right">
                        <li>
                            <a href="#" data-toggle="modal" data-target="#mkdocs_search_modal">
                                <i class="fa fa-search"></i> Search
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        <div class="container">
                <div class="col-md-3"><div class="bs-sidebar hidden-print affix well" role="complementary">
    <ul class="nav bs-sidenav">
        <li class="main active"><a href="#web3db">web3.db</a></li>
            <li><a href="#web3dbputstring">web3.db.putString</a></li>
            <li><a href="#web3dbgetstring">web3.db.getString</a></li>
            <li><a href="#web3dbputhex">web3.db.putHex</a></li>
            <li><a href="#web3dbgethex">web3.db.getHex</a></li>
    </ul>
</div></div>
                <div class="col-md-9" role="main">

<h1 id="web3db">web3.db</h1>
<p>web3.db 存储数据相关的接口</p>
<h2 id="web3dbputstring">web3.db.putString</h2>
<pre><code class="js">    web3.db.putString(db, key, value)
</code></pre>

<p>使用putString()方法在本地leveldb数据库中存储字符串.</p>
<h3 id="_1">参数</h3>
<ol>
<li><code>db</code>: <code>String</code> - 存储数据库名称.</li>
<li><code>key</code>: <code>String</code> - 存储键名.</li>
<li><code>value</code>: <code>String</code> - 要存入的字符串.</li>
</ol>
<h3 id="_2">返回值</h3>
<p><code>Boolean</code> - 成功返回<code>true</code>，否则返回<code>false</code></p>
<h3 id="_3">示例</h3>
<pre><code class="js">web3.db.putString('testDB', 'key', 'myString') // true
</code></pre>

<hr />
<h2 id="web3dbgetstring">web3.db.getString</h2>
<pre><code class="js">    web3.db.getString(db, key)
</code></pre>

<p>从本地leveldb数据库获取字符串。</p>
<h3 id="_4">参数</h3>
<ol>
<li><code>db</code>: <code>String</code> - 目标数据库名称.</li>
<li><code>key</code>: <code>String</code> - 要读取的键.</li>
</ol>
<h3 id="_5">返回值</h3>
<p><code>String</code> - 返回对应键所保存的字符串.</p>
<h3 id="_6">示例</h3>
<pre><code class="js">var value = web3.db.getString('testDB', 'key');
console.log(value); // &quot;myString&quot;
</code></pre>

<hr />
<h2 id="web3dbputhex">web3.db.putHex</h2>
<pre><code class="js">    web3.db.putHex(db, key, value)
</code></pre>

<p>使用putHex()方法在本地leveldb数据库中以二进制存储方式存入 16进制字符串.</p>
<h3 id="_7">参数</h3>
<ol>
<li><code>db</code>: <code>String</code> - 目标数据库名称.</li>
<li><code>key</code>: <code>String</code> - 目标键名称.</li>
<li><code>value</code>: <code>String</code> - 要保存的16进制字符串.</li>
</ol>
<h3 id="_8">返回值</h3>
<p><code>Boolean</code> - 成功时返回<code>true</code>，失败时返回<code>false</code>.</p>
<h3 id="_9">示例</h3>
<pre><code class="js">web3.db.putHex('testDB', 'key', '0x4f554b443'); // true

</code></pre>

<hr />
<h2 id="web3dbgethex">web3.db.getHex</h2>
<pre><code class="js">    web3.db.getHex(db, key)
</code></pre>

<p>使用getHex()方法从本地leveldb数据库中读取指定键的16进制格式字符串.</p>
<h3 id="_10">参数</h3>
<p>1.<code>db</code>: <code>String</code> - 目标数据库.
2.<code>key</code>: <code>String</code> - 要读取的键名称.</p>
<h3 id="_11">返回值</h3>
<p><code>String</code> - 16进制字符串值.</p>
<h3 id="_12">示例</h3>
<pre><code class="js">var value = web3.db.getHex('testDB', 'key');
console.log(value); // &quot;0x4f554b443&quot;
</code></pre>

<hr /></div>
        </div>

        <footer class="col-md-12">
            <hr>
            <p>Documentation built with <a href="https://www.mkdocs.org/">MkDocs</a>.</p>
        </footer>
        <script>
            var base_url = "..",
                shortcuts = {"help": 191, "next": 78, "previous": 80, "search": 83};
        </script>
        <script src="../js/base.js" defer></script>
        <script src="../search/main.js" defer></script>

        <div class="modal" id="mkdocs_search_modal" tabindex="-1" role="dialog" aria-labelledby="Search Modal" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="exampleModalLabel">Search</h4>
            </div>
            <div class="modal-body">
                <p>
                    From here you can search these documents. Enter
                    your search terms below.
                </p>
                <form role="form">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="Search..." id="mkdocs-search-query" title="Type search term here">
                    </div>
                </form>
                <div id="mkdocs-search-results"></div>
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div><div class="modal" id="mkdocs_keyboard_modal" tabindex="-1" role="dialog" aria-labelledby="Keyboard Shortcuts Modal" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="exampleModalLabel">Keyboard Shortcuts</h4>
            </div>
            <div class="modal-body">
              <table class="table">
                <thead>
                  <tr>
                    <th style="width: 20%;">Keys</th>
                    <th>Action</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td class="help shortcut"><kbd>?</kbd></td>
                    <td>Open this help</td>
                  </tr>
                  <tr>
                    <td class="next shortcut"><kbd>n</kbd></td>
                    <td>Next page</td>
                  </tr>
                  <tr>
                    <td class="prev shortcut"><kbd>p</kbd></td>
                    <td>Previous page</td>
                  </tr>
                  <tr>
                    <td class="search shortcut"><kbd>s</kbd></td>
                    <td>Search</td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div>

    </body>
</html>
